#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <cstdlib>
#include <ctime>

#define N 27

using namespace std; 

int n; 
string a, b, c; 
int val[256]; 
char num[N]; 

void init_val(void)
{
	int i; 
	for (i='A'; i<='Z'; i++) {
		val[i] = -1; 
	}
}

bool infer(int bit, int carry)
{
	int  sa, ea, sb, eb, i, j, k, v, nc, nv, o = n-1-bit; 
	char ch[3]; 
	int org_val[3]; 
	bool r; 

	if (bit==n) {
		if (carry==0) {
			cout<<"ret true, line="<<__LINE__<<" bit="<<bit<<endl; 
			return true; 
		} else {
			cout<<"ret false, line="<<__LINE__<<" bit="<<bit<<endl; 
			return false; 
		}
	}
	
	ch[0] = a[o]; 
	ch[1] = b[o]; 
	ch[2] = c[o]; 
	cout<<endl<<"infer: bit="<<bit<<" "<<ch[0]<<" + "<<ch[1]<<" = "<<ch[2]<<endl; 
	for (j=0; j<3; j++) {
		org_val[j] = val[(int)ch[j]]; 
	}
	if (org_val[0]<0) {
		cout<<" line="<<__LINE__<<" org_val[0]="<<org_val[0]<<endl; 
		sa = 0; 
		ea = n-1; 
	} else {
		cout<<" line="<<__LINE__<<" org_val[0]="<<org_val[0]<<endl; 
		sa = org_val[0]; 
		ea = org_val[0]; 
	}
	if (org_val[1]<0) {
		cout<<" line="<<__LINE__<<" org_val[1]="<<org_val[1]<<endl; 
		sb = 0; 
		eb = n-1; 
	} else {
		cout<<" line="<<__LINE__<<" org_val[1]="<<org_val[1]<<endl; 
		sb = org_val[1]; 
		eb = org_val[1]; 
	}
	cout<<" sa="<<sa<<" ea="<<ea<<" sb="<<sb<<" eb="<<eb<<endl; 
	
	for (i=sa; i<=ea; i++) {
		if (num[i] && num[i]!=ch[0]) {
			cout<<"continue, "<<"bit="<<bit<<" i="<<i<<", line="<<__LINE__<<endl; 
			continue; 
		}
		
		for (j=sb; j<=eb; j++) {
			if (bit==0 && i==4 && j==2) 
				cout<<"****************"<<endl; 
				
			if (num[j] && num[j]!=ch[1]) {
				cout<<"continue, "<<"bit="<<bit<<" i="<<i<<" j="<<j<<", line="<<__LINE__<<endl; 
				continue;
			} 
			v = i + j + carry; 
			nc = v / n; 
			nv = v % n; 
			if (org_val[2]>=0) {
				if (nv!=org_val[2]) {
					cout<<"continue, "<<"bit="<<bit<<" i="<<i<<" j="<<j<<", line="<<__LINE__<<endl; 
					continue; 
				}
			}
			if (num[nv] && num[nv]!=ch[2]) {
				cout<<"continue, "<<"bit="<<bit<<" i="<<i<<" j="<<j<<", line="<<__LINE__<<endl; 
				continue; 
			}
			if ((ch[0]==ch[1] && i!=j) || 
				(ch[0]==ch[2] && i!=nv) || 
				(ch[2]==ch[1] && nv!=j) ||
				(ch[0]!=ch[1] && i==j) || 
				(ch[0]!=ch[2] && i==nv) || 
				(ch[2]!=ch[1] && nv==j)) {
				cout<<"continue, "<<"bit="<<bit<<" i="<<i<<" j="<<j<<", line="<<__LINE__<<endl; 
				continue; 
			}
			cout<<"bit="<<bit<<" carry="<<carry<<" i="<<i<<" j="<<j<<" nv="<<nv<<" nc="<<nc<<endl; 
			val[(int)ch[0]] = i; 
			val[(int)ch[1]] = j; 
			val[(int)ch[2]] = nv; 
			num[i] = ch[0]; 
			num[j] = ch[1]; 
			num[nv] = ch[2]; 
			
			r = infer(bit+1, nc); 
			if (r==true) {
				return true; 
			}
			num[i] = 0; 
			num[j] = 0; 
			num[nv] = 0; 
			for (k=0; k<3; k++) {
				val[(int)ch[k]] = org_val[k]; 
			}
			cout<<"continue, "<<"bit="<<bit<<" i="<<i<<" j="<<j<<", line="<<__LINE__<<endl; 
		}
	}
	cout<<"ret false, line="<<__LINE__<<" bit="<<bit<<endl; 
	return false; 
}

int main()
{
	int i; 
	bool ret; 
	freopen("p1092.in", "r", stdin); 
	cin>>n; 
	cin>>a>>b>>c; 

	cout<<n<<endl; 
	cout<<a<<endl; 
	cout<<b<<endl; 
	cout<<c<<endl; 

	for (i=0; i<n; i++) {
		val['A'+i] = -1; 
	}

	ret = infer(0, 0); 

	cout<<ret<<endl; 
	for (i=0; i<n; i++) {
		cout<<val[(int)'A'+i]<<" "; 
	}
	cout<<endl; 

	return 0; 
}

